import psycopg2

def get_pg_tables():
    conn = psycopg2.connect(
        host="127.0.0.1",
        database="wuhandb",
        user="postgres",
        password="egova"
    )
    query_sql = """
            SELECT 
                f_table_name as table_name,
                type as geometry_type,
                srid as srid
            FROM geometry_columns
            WHERE f_table_schema NOT IN ('information_schema', 'pg_catalog')
        """
    names = []
    try:
        # 使用可滚动游标
        with conn.cursor() as cursor:
            cursor.execute(query_sql)
            while True:
                rows = cursor.fetchmany(100)
                if not rows:
                    break

                for row in rows:
                    table_name, type, srid = row
                    names.append((table_name, srid))

    except Exception as e:
        conn.rollback()
        print(f"查询失败: {e}")
    finally:
        conn.close()
    return names